package sk.atletis.atletika;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.support.v4.app.NotificationCompat;

public class NotificationReceiver extends BroadcastReceiver 
{
	private static final int NOTIFICATION_ID = 1;

	@Override
	public void onReceive(Context context, Intent incoming) 
	{
		NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
		
		notificationManager.cancel(NOTIFICATION_ID);
		
		int newArticles = incoming.getIntExtra(ArticlesContract.NEW_ARTICLES, 0);
		
		if (newArticles > 0)
		{
			Resources res = context.getResources();
			
			Notification n;
			NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
			
			Intent intent = new Intent(context, MainActivity.class);
			PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
			
			n = builder
					.setContentTitle(res.getString(R.string.app_name))
					.setContentText(res.getString(R.string.new_articles))
					.setSmallIcon(R.drawable.ic_launcher)
					.setContentIntent(pi)
					.setNumber(newArticles)
					.setStyle(new NotificationCompat.BigTextStyle().bigText(String.valueOf(newArticles)))
					.build();
			
			notificationManager.notify(NOTIFICATION_ID, n);
		}
		else
			return;

		
	}
}
